<template>
  <div class="chat-main">
    <div v-if="activeSession" class="chat-content">
      <div class="chat-messages">
        <div class="empty-tip">当前会话：{{ activeSession.name }}</div>
      </div>
      <div class="chat-input">
        <el-input
            v-model="inputMessage"
            placeholder="输入消息..."
            type="textarea"
            :rows="3"
            @keyup.enter="handleSend"
        />
        <el-button type="primary" class="send-btn" @click="handleSend">发送</el-button>
      </div>
    </div>
    <div v-else class="empty-chat">
      请选择或新建会话
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'

const props = defineProps({
  activeSession: Object
})

const emit = defineEmits(['send-message']) // 添加事件

const inputMessage = ref('')

const handleSend = () => {
  if (!inputMessage.value.trim()) return
  emit('send-message', inputMessage.value.trim())
  inputMessage.value = '' // 清空输入
}
</script>

<style scoped>
/* 保持原有样式 */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.chat-content {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.chat-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
}

.chat-input {
  padding: 20px;
  border-top: 1px solid #e4e7ed;
}

.send-btn {
  margin-top: 10px;
}

.empty-chat {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #909399;
}
</style>
